package condition;

import roborally.Position;
import elements.Element;

/**
 * A class of ternary basic conditions.
 * 
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 *
 */
public class SubRange extends TernaryBasicCondition{
	
	/**
	 * @pre	The begin position is the position to the upper left of the box we want to examine. (the position inclusive)
	 * 		The end position is the position to the lower right of the box we want to examine. (the position inclusive)
	 * @param 	begin
	 * 			The position to the upper left of the box we want to examine. (the position inclusive)
	 * @param 	end
	 * 			The position to the lower right of the box we want to examine. (the position inclusive)
	 */
	public SubRange(Position begin, Position end) {
		super(begin, end);
		assert(begin.getX() <= end.getX() && begin.getY() <= end.getY());
	}

	/**
	 * Returns true if the given element is located in the box surrounded by begin and end. (these positions inclusive)
	 */
	@Override
	public boolean evaluate(Element element) {
		if(element.getBoard()==null || element.getPosition()==null){
			return false;
		}
		else{
			if(element.getPosition().getX() >= begin.getX() && element.getPosition().getY() >= begin.getY()
					&& element.getPosition().getX() <= end.getX() && element.getPosition().getY() <= end.getY()){
				return true;
			}
			return false;
		}
	}
	
	@Override
	public String toString(){
		return "( between " +this.begin+" "+this.end + " )";
	}
	
	@Override
	public boolean equals(Object object){
		if(object == null || this==null){
			return false;
		}
		return this.toString().equals(object.toString());
	}

}
